import redis

#定义地址和端口
host = '127.0.0.1'
#定义docker中的redis端口
# host = '192.168.99.100'
port = 6379
#docker中redis的端口号
# port = 6380

#建立redis连接
r = redis.Redis(host=host,port=port)

#set
# #声明一个值
# r.set('test','321')
#
# #取值
# code = r.get('test')
#
# print(type(code))
#
# #转码
# code = code.decode('utf-8')
#
# print(code)

#set的sadd
# list_a = ['爆款','修身']
# #2020.03.26
# r.sadd('testset',list_a[0])
# #再添加一个爆款
# r.sadd('testset',list_a[0])
#
# r.sadd('testset',list_a[1])
#
# #查询
# myset = r.smembers('testset')
# print(myset)
# #强转为字符串
# myset = list(myset)
# mytag = str(myset[0],'utf-8')
#
# print(mytag)
#
# #删除集合
# r.delete('testset')
#
# print(myset)

#list使用
r.lpush('testlist',1)

print(r.llen('testlist'))

mylist = r.lrange('testlist',0,r.llen('testlist'))

# r.delete('testlist')      #可以删除信息

print(mylist)